package common;/*
 *
 * @author lileilei
 * Date: 2018/11/27
 * Time: 11:40
 */

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;


public class StringJsonParson {
    public static Map<String, Object> json2map(String str_json) {
        Map<String, Object> res;
        Gson gson = new Gson();
        res = gson.fromJson(str_json, new TypeToken<Map<String, Object>>() {
            }.getType());
        return res;
    }
    public static Map<String, Object> json2newmap(String str_json) {
        Map<String, Object> res = new HashMap<String, Object>();
        Gson gson = new Gson();
        res = gson.fromJson(str_json, res.getClass());
        return res;
    }

    public static String makejson(Map<String, Object> map) {
        try {
            Gson gson = new Gson();
            String param1 = gson.toJson(map);
            return param1;
        } catch (Exception e) {
           e.printStackTrace();
           return null;
        }
    }
}
